package com.telecom.cms.actions;

import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.telecom.cms.dao.SEG_ATOM_GROUP_RELDAO;
import com.telecom.cms.dao.SEG_BIZ_ATOM_DEFDAO;
import com.telecom.cms.dao.SEG_BIZ_GROUP_DEFDAO;
import com.telecom.cms.dao.GetConnect;
import com.telecom.cms.dto.*;


/**
 * @author yueyingnishang
 * 
 */
public class AtomgetAction extends Action {

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.apache.struts.action.Action#execute(org.apache.struts.action.ActionMapping,
	 *      org.apache.struts.action.ActionForm,
	 *      javax.servlet.http.HttpServletRequest,
	 *      javax.servlet.http.HttpServletResponse)
	 */
	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		// TODO Auto-generated method stub
		Connection con = GetConnect.getCsConnection();

		int bookmarkid = Integer.parseInt(request.getParameter("bookmarkid"));
		SEG_BIZ_GROUP_DEFDAO seg_BIZ_GROUP_DEFDAO = new SEG_BIZ_GROUP_DEFDAO(
				con);
		List gplist = seg_BIZ_GROUP_DEFDAO.findById(bookmarkid);
		request.setAttribute("Group", gplist);
		// group
		int id = Integer.parseInt(request.getParameter("groupid"));
		SEG_ATOM_GROUP_RELDAO agdao = new SEG_ATOM_GROUP_RELDAO(con);
		List aglist = agdao.findById(id);
		List atomlist = new ArrayList();
		for (int i = 0; i < aglist.size(); i++) {
			SEG_ATOM_GROUP_RELDTO seg_ATOM_GROUP_RELDTO = (SEG_ATOM_GROUP_RELDTO) aglist
					.get(i);
			SEG_BIZ_ATOM_DEFDAO dao = new SEG_BIZ_ATOM_DEFDAO(con);
			SEG_BIZ_ATOM_DEFDTO dto = dao.findById(seg_ATOM_GROUP_RELDTO
					.getBIZ_ATOM_ID());
			if (null!=dto && null != dto.getBAS_TABLE_NAME()&&dto.getSHOW_TYPE_ID()!= 100) {
				atomlist.add(dto);
			}
		}
		request.setAttribute("Atoms", atomlist);
		request.setAttribute("id", id);

		return mapping.findForward("success");
	}
}
